#include <bits/stdc++.h>
// 2025/02/05
// tag:
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

int n, rp, money, dp[105][105], t[105][105], mm[105][3];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> mm[i][0] >> mm[i][1] >> mm[i][2];
    cin >> money >> rp;
    for (int k = 1; k <= n; k++)
        for (int i = money; i >= mm[k][0]; i--)
            for (int j = rp; j >= mm[k][1]; j--)
                if (dp[i][j] < dp[i - mm[k][0]][j - mm[k][1]] + 1)
                    dp[i][j] = dp[i - mm[k][0]][j - mm[k][1]] + 1, t[i][j] = t[i - mm[k][0]][j - mm[k][1]] + mm[k][2];
                else if (dp[i][j] == dp[i - mm[k][0]][j - mm[k][1]] + 1)
                    t[i][j] = min(t[i][j], t[i - mm[k][0]][j - mm[k][1]] + mm[k][2]);
    cout << t[money][rp];
    return 0;
}